package com.example.friend.controller;

import com.example.core.controller.BaseController;
import com.example.core.entity.PageDataInfo;
import com.example.core.result.Res;
import com.example.friend.entity.DTO.ExamQueryDTO;
import com.example.friend.entity.VO.ExamVO;
import com.example.friend.service.IExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    @GetMapping("/semiLogin/list")
    public PageDataInfo<ExamVO> list(ExamQueryDTO examQueryDTO) {
        return examService.list(examQueryDTO);
    }

    @GetMapping("/getFirstQuestion")
    public Res<String> getFirstQuestion(Long examId) {
        // 代码逻辑： 获取竞赛中题目的顺序列表   先从redis  redis中没有数据查询数据库  list  数据类型  key: e:q:l:examId   value : questionId
        // 排在第一个的题目  返回给前端
        return Res.ok(examService.getFirstQuestion(examId));
    }

    @GetMapping("/preQuestion")
    public Res<String> preQuestion(Long examId, Long questionId) {
        return Res.ok(examService.preQuestion(examId, questionId));
    }

    @GetMapping("/nextQuestion")
    public Res<String> nextQuestion(Long examId, Long questionId) {
        return Res.ok(examService.nextQuestion(examId, questionId));
    }

}
